﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace frmCheckStock
{
    public partial class frmPurchaseList : Form
    {
       LogicUniversityT2Entities logic;
       double totalAmount = 0.0;
       ////DataGridTableStyle dgstyle;
       //DataGridTextBoxColumn iNoCol;
       
        public frmPurchaseList()
        {
            InitializeComponent();
         }

        private void frmPreparePurchaseList_Load(object sender, EventArgs e)
        {
            lblDate.Text = DateTime.Now.ToShortDateString();
       
            logic=new LogicUniversityT2Entities();
             var purchaselist =from itemDetail in logic.ItemDetails
                               join item in logic.Items on itemDetail.ItemID equals item.ItemID
                               join supplier in logic.Suppliers on itemDetail.SupplierID equals supplier.SupplierID
                              where itemDetail.Item.StockBalance < itemDetail.Item.ReorderQuantity
                              select new{
                              Item_No = itemDetail.ItemID,
                              Item_Description=itemDetail.Item.ItemDescription,
                              Supplier_Name=itemDetail.Supplier.SupplierName,
                              Quantity=(item.ReorderLevel.Value+item.StockBalance.Value),
                              Price =itemDetail.Price,
                              Amount_Item = (item.ReorderLevel.Value + item.StockBalance.Value) * itemDetail.Price,
                              
                               };
             
            var plist=purchaselist.ToList();
             dgPurchaseList.DataSource = plist;
             foreach (var total in purchaselist)
             {
                double amount = Convert.ToDouble(total.Amount_Item);
                totalAmount += amount;
                 lblTotalAmount.Text = totalAmount.ToString();
              }   
            
            

            //dgstyle = new DataGridTableStyle();
            //iNoCol = new DataGridTextBoxColumn();
            //iNoCol.MappingName = "Item_No";
            //iNoCol.HeaderText = "Item No";
            //iNoCol.Width = 140;
            //dgstyle.GridColumnStyles.Add(iNoCol);

            //DataGridTextBoxColumn iDesCol = new DataGridTextBoxColumn();
            //iDesCol.MappingName = "Item_Description";
            //iDesCol.HeaderText = "Item Description";
            //iDesCol.Width = 140;
            //dgstyle.GridColumnStyles.Add(iDesCol);

            //DataGridViewComboBoxColumn iSupCol = new DataGridViewComboBoxColumn();
            //iSupCol.MaxDropDownItems = 10;
            //iSupCol.HeaderText = "Supplier Name";
            //iSupCol.Width = 140;
            //dgstyle.GridColumnStyles.Add(iSupCol);

            //DataGridTextBoxColumn iQtyCol = new DataGridTextBoxColumn();
            //iQtyCol.MappingName = "Quantity";
            //iQtyCol.HeaderText = "Quantity";
            //iQtyCol.Width = 140;
            //dgstyle.GridColumnStyles.Add(iQtyCol);

            //DataGridTextBoxColumn iPriCol = new DataGridTextBoxColumn();
            //iPriCol.MappingName = "Price";
            //iPriCol.HeaderText = "Price";
            //iPriCol.Width = 140;
            //dgstyle.GridColumnStyles.Add(iPriCol);

            //DataGridTextBoxColumn iAmoCol = new DataGridTextBoxColumn();
            //iAmoCol.MappingName = "Amount_Item";
            //iAmoCol.HeaderText = "Amount_Item";
            //iAmoCol.Width = 140;
            //dgstyle.GridColumnStyles.Add(iAmoCol);


            //dgPurchaseList.TableStyles.Add(dgstyle);
            }

        private void btnProceed_Click(object sender, EventArgs e)
        {
            logic.SaveChanges();
        }
    }
}
